import { UserProfilesAPI } from "@/request/api"

export default {
    namespaced: true,
    state: {
        userInfo: {
            //头像
            headImg: require("../../assets/img/service.848ec511.png"),
            //昵称
            nickName: "--",
            //积分
            coin: "--"
        },
        //购物车总数
        cartTotal: 9
    },
    mutations: {
        changeUserInfo(state, payload) {
            console.log("mutation");
            state.userInfo = payload.userInfo
            state.cartTotal = payload.cartTotal
        },
        initUserInfo(state) {
            state.userInfo = {
                //头像
                headImg: require("../../assets/img/userImg.f8bbec5e.png"),
                //昵称
                nickName: "--",
                //积分
                coin: "--"
            },
                //购物车总数
                state.cartTotal = 0
        },
    },
    actions: {
        async asyncChangeUserInfo({ commit }, payload) {
            let res = await UserProfilesAPI();
            console.log("actions", res.data);
            commit("changeUserInfo", res.data)
        }
    }
}